====== Escape from Goblin-town! ======

<blockquote>
Still goblins go faster than dwarves, and these goblins knew the way better (they had made the paths themselves), and were madly angry; so that do what they could the dwarves heard the cries and howls getting closer and closer. Soon they could hear even the flap of the goblin feet, many many feet which seemed only just round the last corner. The blink of red torches could be seen behind them in the tunnel they were following; and they were getting deadly tired.
<cite>[[https://books.google.ca/books?id=hFfhrCWiLSMC&pg=PA66&lpg=PA66&dq=Still+goblins+go+faster+than+dwarves,+and+these+goblins+knew+the+way+better&source=bl&ots=YDv8tHpycE&sig=3aDb3Th-DGYCjryA-J1CPXioa4I&hl=en&sa=X&ved=0ahUKEwjb18zHmpPOAhUH7oMKHaaKCHEQ6AEIJTAC#v=onepage&q&f=false | J.R.R. Tolkien, "The Hobbit"]]</cite>
</blockquote>

The following simulation is inspired by the Goblin-town chase scene in the film [[http://www.imdb.com/title/tt0903624/ | The Hobbit: An Unexpected Journey]].

{{url>https://www.youtube.com/embed/IccbfvmsgTI 560,315px}}

The NetLogo model below simulates a set of platforms and bridges, shown from above. Dwarves (brown) are trying to get from the top-left corner, past the goblins (green), to the escape in the bottom-right corner.  To see how it works, press ''setup'' and, after waiting a few seconds for the scene to be prepared, press ''go''.

You'll see that the dwarves and goblins are both pretty dumb -- they just stumble around randomly.  If a dwarf should happen to find the escape, it's just dumb luck.

Can you do better?  You can edit the code in this simulation to try help the dwarves (or goblins).  Click **NetLogo Code** at the bottom and take a look at these procedures:
<code>
to turn-dwarf
  ;;;;;; YOUR CODE GOES HERE!
   face-random-direction
end

;---------------------------------------------------------

to turn-goblin
  ;;;;;; YOUR CODE GOES HERE!
  face-random-direction
end
</code>

The command ''face-random-direction'' is a [[https://ccl.northwestern.edu/netlogo/docs/tutorial3.html | procedure]] I wrote.  But it's not very useful.  Have a look at the other ''face-...'' procedures in the **NetLogo Code** below.  Maybe one of those would be better?  Go ahead and replace the command ''face-random-direcion'' in the ''turn-dwarf'' or ''turn-goblin'' procedure, then click **Recompile Code** to try it out.  Did your changes work the way you expected?  (If not, see if you can figure out why not and try again :-) )

{{ https://raw.githubusercontent.com/rikblok/NetLogo-models/master/goblin-town.nlogo?770x1210 }}

====== Submit your code ======

Did you write some amazing ''turn-dwarf'' or ''turn-goblin'' code?  Submit it here!  I might add it to the simulation!

{{url>http://www.zoology.ubc.ca/~rikblok/wiki/doku.php?id=science:popmod:goblintown:submitcode 780,600px}}


====== Share =======

Like this page?  Share it!

~~lsb~~

====== Comments ======

~~DISQUS~~
